<?php
/**
 * Created by PhpStorm.
 * User: Mikkle
 * QQ:776329498
 * Date: 2017/12/19
 * Time: 14:23
 */

namespace app\index\controller;

use app\api\controller\base\Base;
use app\base\service\center\OptionsCenter;
use mikkle\tp_tools\DataEdit;
use mikkle\tp_tools\ShowCode;
use think\Exception;
use think\Log;
/**
 * @title 收费员接口类
 * @description
 * @group APP接口
 * Class Charge
 * @package app\api\controller\app
 */
class Charge
{


    /**
     * @title 收费员登录班次站点
     * @description 终端测试号 861373020508882
     * @author Mikkle
     * @url  /api/app.charge/chargeDispatchLogin
     * @method POST
     * @param_send name:dispatch_id type:int require:1 default:15000002 other:8位数字 desc:班次编号ID
     * @param_send name:charge_id type:int require:1 default:17000002 other:8位数字 desc:收费员ID
     * @param_send name:charge_password type:string require:1 default:1111 other:40字符串 desc:收费员密码
     * @param_send name:terminal_mac type:string require:1 default: other:40字符串 desc:设备终端码
     * @param_return charge_name:收费员姓名
     * @param_return charge_token:收费员登录码
     */
    public function chargeDispatchLogin(){
        try{
            $operate = DataEdit::instance();
            $result = $operate->setParameter([
                OptionsCenter::$idDispatch =>OptionsCenter::$idDispatch,
                OptionsCenter::$idCharge =>OptionsCenter::$idCharge,
                OptionsCenter::$fieldChargePassword=>OptionsCenter::$fieldChargePassword,
                OptionsCenter::$fieldTerminalMac => OptionsCenter::$fieldTerminalMac,
            ])->setValidate(false)
                ->setModel("base/app/Charge")
                ->setModelType("service")
                ->execModelAction("chargeDispatchLogin");
            if ($result===false){
                throw new Exception($operate->getError());
            }
            return $result;
        }catch (Exception $e){
            Log::error($e);
            return ShowCode::jsonCodeWithoutData(1008,$e->getMessage());
        }
    }

    /**
     * @title 收费员下班签退接口
     * @description  最新更改 签退后清除Token信息  获取日报信息已取消验证
     * @author Mikkle
     * @url  /api/app.charge/signLogout
     * @method POST
     * @param_send name:charge_token type:string require:1 default: other: desc:登录Token
     * @param_return document_id:当前日报Id
     */
    public function signLogout(){
        try{
            $operate = DataEdit::instance();
            $result = $operate->setParameter([
                OptionsCenter::$fieldChargeToken =>OptionsCenter::$fieldChargeToken,
            ])->setValidate(false)
                ->setModel("base/app/Charge")
                ->setModelType("service")
                ->execModelAction("chargeSignLogout");
            if ($result===false){
                throw new Exception($operate->getError());
            }
            return $result;
        }catch (Exception $e){
            Log::error($e);
            return ShowCode::jsonCodeWithoutData(1008,$e->getMessage());
        }
    }

    /**
     * @title 收费员修改登录密码
     * @description
     * @author Mikkle
     * @url  /api/app.charge/editPassword
     * @method POST
     * @param_send name:charge_token type:string require:1 default: other: desc:登录Token
     * @param_send name:old_password type:string require:1 default: other: desc:旧密码
     * @param_send name:new_password type:string require:1 default: other: desc:新密码
     * @param_send name:repeat_new_password type:string require:1 default: other: desc:重复新密码
     * @param_return document_id:当前日报Id
     */
    public function editPassword(){
        try{
            $operate = DataEdit::instance();
            $result = $operate->setParameter([
                OptionsCenter::$fieldChargeToken =>OptionsCenter::$fieldChargeToken,
                "old_password"=>"old_password",
                "new_password"=>"new_password",
                "repeat_new_password"=>"repeat_new_password",
            ])->setValidate(false)
                ->setModel("base/app/Charge")
                ->setModelType("service")
                ->execModelAction("editPassword");
            if ($result===false){
                throw new Exception($operate->getError());
            }
            return $result;
        }catch (Exception $e){
            Log::error($e);
            return ShowCode::jsonCodeWithoutData(1008,$e->getMessage());
        }
    }


    /**
     * @title 获取收费员即时日报详情
     * @description   注意 收费员签退成功时候 此接口会无效
     * @author Mikkle
     * @url  /api/app.charge/getDailyDocument
     * @method POST
     * @param_send name:charge_token type:string require:1 default: other: desc:登录Token
     */
    public function getDailyDocument(){
        try{
            $operate = DataEdit::instance();
            $result = $operate->setParameter([
                OptionsCenter::$fieldChargeToken =>OptionsCenter::$fieldChargeToken,
            ])->setValidate(false)
                ->setModel("base/app/Charge")
                ->setModelType("service")
                ->execModelAction("getDailyDocument");
            if ($result===false){
                throw new Exception($operate->getError());
            }
            return $result;
        }catch (Exception $e){
            Log::error($e);
            return ShowCode::jsonCodeWithoutData(1008,$e->getMessage());
        }
    }


    /**
     * @title 获取七日内的收费员日报详情
     * @description  取消了Token验证
     * @author Mikkle
     * @url  /api/app.charge/getDailyDocumentByDocumentId
     * @method POST
     * @param_send name:document_id type:string require:1 default: other: desc:日报Id
     */
    public function getDailyDocumentByDocumentId(){
        try{
            $operate = DataEdit::instance();
            $result = $operate->setParameter([
                OptionsCenter::$idDocument=>"document_id",
            ])->setValidate(false)
                ->setModel("base/app/Charge")
                ->setModelType("service")
                ->execModelAction("getDailyDocumentByDocumentId");
            if ($result===false){
                throw new Exception($operate->getError());
            }
            return $result;
        }catch (Exception $e){
            Log::error($e);
            return ShowCode::jsonCodeWithoutData(1008,$e->getMessage());
        }
    }

    /**
     * @title 收费员生成巡查二维码接口
     * @description
     * @author Mikkle
     * @url  /api/app.charge/getTokenForInspect
     * @method POST
     * @param_send name:charge_token type:string require:1 default: other: desc:登录Token
     */
    public function getTokenForInspect(){
        try{
            $operate = DataEdit::instance();
            $result = $operate->setParameter([
                OptionsCenter::$fieldChargeToken =>OptionsCenter::$fieldChargeToken,
            ])->setValidate(false)
                ->setModel("base/app/Charge")
                ->setModelType("service")
                ->execModelAction("getTokenForInspect");
            if ($result===false){
                throw new Exception($operate->getError());
            }
            return $result;
        }catch (Exception $e){
            Log::error($e);
            return ShowCode::jsonCodeWithoutData(1008,$e->getMessage());
        }
    }



}